<?php


namespace App\Http\Controllers\Estate;


use App\Http\Controllers\Controller;
use App\Models\ElectricMeterReadingLog;
use Illuminate\Http\Request;

/**
 * Class ElectricStatisticsController
 * @package App\Http\Controllers\Estate
 * 能源运维 -- 统计管理控制器
 */
class ElectricStatisticsController extends Controller
{
    /**
     * @param Request $request
     * @return array
     * 电量统计
     */
    public function eleStatistics(Request $request)
    {
        $limit = $request->get('limit', 20);

        $data = ElectricMeterReadingLog::query()->with(['name:id,name', 'address:id,address'])->selectRaw('sum(day_count) as count,id,tableAddress,meter_id,create_time,community_id')->where('type', 1)->groupBy('tableAddress')->paginate($limit);

        return $this->success($data);
    }
}
